var t = getApp()
Page({
  data: {
    resort:false,
    list:[],
    navHeight:t.globalData.navHeight,
    title:'我的余额',
  },
  onLoad: function (options) {
    
  },
  onShow(e){
    this.getlist()
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.getlist()
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  getlist(e){
    var that = this
    var loc = t.globalData.loc
    t.request('/store/index_list',{lat:loc?loc.latitude:0,lng:loc?loc.longitude:0,page:1},function(e){
      console.log(e);
      if (e.code==200) {
        if (e.result.total>0) {
          var list = e.result.list
          for (let i = 0; i < list.length; i++) {
            list[i].distance = list[i].distance.toFixed(1)
          }
          that.setData({
            list:list,
            loc:loc
          })
        }
      }else{
        wx.showToast({
          title: e.msg,
          icon:'none'
        })
      }
    })
  },
  to_invest(e){
    wx.navigateTo({
      url: '/pages/personCenter/chooseStore/invest/invest?store_id=' + e.currentTarget.dataset.store_id,
    })
  },
  open_sort(e){
    this.setData({
      resort:!this.data.resort
    })
  },
  dis_sort(e){
    this.setData({
      resort:false,
    })
  }
})